﻿using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Text.RegularExpressions;
using BLL;
using Model;

public partial class BlotScrew_BlotScrewAdd : System.Web.UI.Page
{
    private BlotScrew bs;

    public BlotScrew_BlotScrewAdd()
    {
        bs = new BlotScrew();
    }

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void TextBox1_TextChanged(object sender, EventArgs e)
    {
        Page.Validate("VGroup1");
        if (Page.IsValid)
        {
            string str = "";
            string productSN = this.TextBox1.Text.Trim();
            if (CommHelper.IsValidSN_forDataAcquisition(productSN))
            {
                productSN = CommHelper.GetProductSN(productSN);
                BlotScrewInfo bsi = new BlotScrewInfo(productSN, DateTime.Now, this.TextBox3.Text.Trim());
                try
                {
                    bs.Insert(bsi);
                    str = " 录入成功！";
                    this.TextBox1.Text = "";
                    this.TextBox1.Focus();
                }
                catch
                {
                    str = "出现错误，请联系相关人员！";
                }
            }
            else
            {
                str = "序列号不符合腔体序列号编码规则，或不是关联过的成品序列号，请检查!";
            }
            ScriptManager.RegisterStartupScript(this.UpdatePanel1, this.GetType(), "click", "<script>alert('" + str + "');</script>", false);
        }
        //else
        //{
        //    foreach (BaseValidator valControl in Page.Validators)
        //    {
        //        if (!valControl.IsValid)
        //        {
        //            str = valControl.ErrorMessage;
        //        }
        //    }
        //}
    }

    protected void Button2_Click(object sender, EventArgs e)
    {
        string productSN = this.TextBox2.Text.Trim();
        productSN = CommHelper.GetProductSN(productSN);
        this.GridView1.DataSource = bs.GetBlotScrewsbySN(productSN);
        this.GridView1.DataBind();
    }
    protected void TextBox3_TextChanged(object sender, EventArgs e)
    {
        this.TextBox1.Focus();        
    }
}
